﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HuntTheWumpus
{
    class Map
    {
        //GameControl gameControl = new GameControl();
        public int WumpusLocation;
        public int Pit1Location;
        public int Pit2Location;
        public int Bat1Location;
        public int Bat2Location;
        public int PlayerLocation;

        public void mainmap()
        {
            
            
            int[] RoomNumber = new int[30];
            // room numbers 
            for (int index = 0; index < 30; index++)
                RoomNumber[index] = index;
            RoomNumber = shuffle(RoomNumber);
            RoomNumber = shuffle(RoomNumber);
            //starting spots of all objects
            WumpusLocation = RoomNumber[1];
            Pit1Location = RoomNumber[2];
            Pit2Location = RoomNumber[3];
            Bat1Location = RoomNumber[4];
            Bat2Location = RoomNumber[5];
            PlayerLocation = RoomNumber[6];
            

            // testing the code
            //int[] testconnections = { 5, 6, 29, 12 };
            //Arrow(WumpusLocation, PlayerLocation, testconnections);
            //Pit1(testconnections, Pit1Location);
            //currentRoom(PlayerLocation);
            //Hint(Pit1Location, Bat1Location, PlayerLocation, Bat2Location, Pit2Location);
            //Pit2(testconnections, Pit2Location);
            //WumpusMovement(testconnections, WumpusLocation);
            //Bat2(testconnections, Bat2Location);
          
        }
        
        // shuffling ints
        int[] shuffle(int[] arr)
        {
            Random rnd = new Random();

            for (int i = 0; i < arr.Length; i++)
            {
                int temp = arr[i];
                int rndVal = rnd.Next(30);
                arr[i] = arr[rndVal];
                arr[rndVal] = temp;
            }

            return arr;
        }
        //shuffling strings
         string[] shufflestring(string[] arr)
        {
            Random rnd = new Random();

            for (int i = 0; i < arr.Length; i++)
            {
                string temp = arr[i];
                int rndVal = rnd.Next(arr.Length);
                arr[i] = arr[rndVal];
                arr[rndVal] = temp;
            }

            return arr;
        }
        //shuffling connections for random wumpus movment
         int[] shufflesmall(int[] arr)
        {
            Random rnd = new Random();

            for (int i = 0; i < arr.Length; i++)
            {
                int temp = arr[i];
                int rndVal = rnd.Next(2);
                arr[i] = arr[rndVal];
                arr[rndVal] = temp;
            }

            return arr;
        }

        //testing connections
        //public int currentRoom(int PlayerLoc)
        //{
        //    int currentroom = PlayerLoc;
        //    return PlayerLoc;
        //}

        public bool IfConnected(int[] connections, int Playerloc)
        {
            bool DisplayHazard = false;

            for (int i = 0; i < connections.Length; i++)
            {
                if (connections[i] == Playerloc)
                {
                    DisplayHazard = true;
                    break;
                }
            }


            return DisplayHazard;
        }    
        //pit Warnings
        public bool Pit1(int[] Connections, int PitLoc)
        {
            bool Pit1Warning = false;
            for (int i = 0; i < Connections.Length; i++)
            {

                if (Connections[i] == PitLoc)
                {
                    Pit1Warning = true;
                    break;
                }
            }
            return Pit1Warning;
        }

        public bool Pit2(int[] Connections, int PitLoc)
        {
            bool Pit2Warning = false;
            for (int i = 0; i < Connections.Length; i++)
            {

                if (Connections[i] == PitLoc)
                {
                    Pit2Warning = true;
                    break;
                }
            }
            return Pit2Warning;
        }
        // Bat Warning
        public bool Bat1(int[] Connections, int BatLoc)
        {
            bool Bat1Warning = false;
            for (int i = 0; i < Connections.Length; i++)
            {

                if (Connections[i] == BatLoc)
                {
                    Bat1Warning = true;
                    break;
                }
            }
            return Bat1Warning;
        }

        public bool Bat2(int[] Connections, int BatLoc)
        {
            bool Bat2Warning = false;
            for (int i = 0; i < Connections.Length; i++)
            {

                if (Connections[i] == BatLoc)
                {
                    Bat2Warning = true;
                    break;
                }
            }
            return Bat2Warning;
        }
        //Wumpus Warning
        public bool WumpusWarn(int[] Connections, int WumpLoc)
        {
            bool WumpWarning = false;
            for (int i = 0; i < Connections.Length; i++)
            {

                if (Connections[i] == WumpLoc)
                {
                    WumpWarning = true;
                    break;
                }
            }
            return WumpWarning;
        }

        //Giving Out Hints
        public string Hint(int pit, int bat, int currentroom, int bat2, int pit2)
        {
            string[] hints = { pit.ToString("Pit Location"), pit2.ToString("Pit Location"), bat.ToString("Bat Location"), bat2.ToString("Bat Location"), currentroom.ToString("CurrentRoom") };
            hints = shufflestring(hints);
            return hints[0];
        }

        // Arrow Hit/Miss
        public bool Arrow(int Wumpus, int Playerloc, int[] connections)
        {
            bool ArrowHit = false;
            for (int i = 0; i < connections.Length; i++)
            {
                if (connections[i] == Playerloc && connections[i] == Wumpus)
                {
                    ArrowHit = true;
                    break;
                }
            }
            return ArrowHit;
        }
        //movments
        public int WumpusMovement(int[] connections, int WumpusLoc)
        {
            
            int Movement;

            shufflesmall(connections);
            Movement = connections[0];
            if (Movement != 0)
            {
                return Movement;
            }
            else
            {
                WumpusMovement(connections, WumpusLoc);
            }
            return Movement;
        }

        public int BatMovement(int[] connections, int BatLoc)
        {

            int Movement;

            shufflesmall(connections);
            Movement = connections[0];

            return Movement;
        }
  
    }


}
